@extends('member.masterCommon')
@section('content')

    <div class="row">
        <div class="col-md-12  header-wrapper" >
            <h1 class="page-header">微信采集文档列表</h1>
            <p class="page-subtitle">微信采集文档都在这里啦</p>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <ol class="breadcrumb">
        <li><a href="{{url('member/archives/master')}}">内容管理</a></li>
        <li class="active">微信采集文档列表</li>
    </ol>

    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <p>
                    <button type="button" class="btn btn-primary btn-xs start" ><i class="fa fa-search"></i> 开始采集</button>
                    <button type="button" class="btn btn-warning btn-xs stop" ><i class="fa fa-search"></i> 停止采集</button>
                    <button type="button" class="btn btn-success btn-xs checked_all"><i class="fa fa-arrows"></i> 全选</button>
                    <button type="button" class="btn btn-danger btn-xs delete_archives"><i class="fa fa-times"></i> 删除</button>
                    <a href ="{{url('member/wechat/txt').'/all'}}"  type="button" class="btn btn-default btn-xs"><i class="fa fa-file"></i> 全部导出</a>
                    <a href ="{{url('member/wechat/txt').'/500'}}"  type="button" class="btn btn-default btn-xs"><i class="fa fa-file"></i> 导出最新500条</a>
                    <a href ="{{url('member/wechat/txt').'/1000'}}"  type="button" class="btn btn-default btn-xs"><i class="fa fa-file"></i> 导出最新1000条</a>
                    <a href ="{{url('member/wechat/txt').'/2000'}}"  type="button" class="btn btn-default btn-xs"><i class="fa fa-file"></i> 导出最新2000条</a>
                </p>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <form>
                        <label>搜索:<input type="search" class="form-control" placeholder="" name="s" id="search" ></label>
                    </form>
                </div>
            </div>
            <table class="table table-bordered table-hover" id="dataTables-userlist">
                <thead>
                <tr>
                    <th><input type="checkbox" class="checked_all"/> </th>
                    <th>ID </th>
                    <th>标题 </th>
                    <th>时间</th>
                    <th>发布者</th>
                    <th>标签</th>
                    <th width="100">点击</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($archives as $a)
                    <tr>
                        <td><input type="checkbox" name="check" data-id="{{ $a->id }}" /></td>
                        <td>{{$a->id}}</td>
                        <td>
                            @if($a->cover)
                                <img src="{{route('image', [$a->cover, '30x30'])}}" onerror="$(this).remove()" alt="" class="gridpic">
                            @endif
                            {{$a->title}}<br>
                        </td>
                        <td>{{$a->created_at}}</td>
                        <td class="center">{{$a->wechat->author}}</td>
                        <td class="center">
                            @foreach($a->tags as $tag)
                            <a href="{{$tag->url }}" target="_blank" class="btn btn-primary btn-xss">{{$tag->name}}</a>
                            @endforeach
                        </td>
                        <td class="center">{{$a->visit_count}}</td>
                        <td class="center">
                            <a href="{{route('archives.edit', [$a->id, 'master'])}}" class="btn btn-circle btn-primary ">编辑</a>
                            <a href="{{route('article.show', [$a->id])}}" class="btn btn-circle btn-success " target="_blank">预览</a>
                            <a href="javascript:void(0)" class="btn btn-circle btn-danger delete-archives" data-id="{{$a->id}}">删除</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="row"><div class="col-sm-6"><div class="dataTables_info" id="dataTables-userlist_info" role="status" aria-live="polite">每页显示20条数据，一共{{$count}}数据</div></div>
            <div class="col-sm-6">
                <div class="dataTables_paginate paging_full_numbers" id="dataTables-userlist_paginate">
                    {{$archives->links()}}
                </div>
            </div>
        </div>
    </div>
    <!-- /.row -->
    <script>
        $(function(){



           $('.start').click(function(){
               var _this = $(this);
               $.get("{{route('spider_start')}}",{},function(data){
                   if(data.error_code==0){
                       layer.msg('启动成功！');
                       _this.addClass('disabled');
                   }
               })
           })
            $('.stop').click(function(){
                var _this = $(this);
                $.get("{{route('spider_stop')}}",{},function(data){
                    if(data.error_code==0){
                        layer.msg('关闭成功！');
                        _this.addClass('disabled');
                    }
                })
            })
        });

        $('.delete-archives').click(function(){
            var $this = $(this);
            var id = $(this).data('id');
            var token = "{{csrf_token()}}";
            layer.confirm('确认删除文章?', {
                title: '删除确认',
                btn: ['确认','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{{url('member/archives/modDestroy')}}" + '/' + id,
                    data:{_token:token},
                    type:'get',
                    success:function(data){
                        if(data=='success'){
                            layer.msg('删除成功!', {icon: 1});
                            $this.parents('tr').remove();
                        }else{
                            layer.msg('删除失败!', {icon: 2});
                        }
                    }
                });

            });
        });

        //全选和删除
        $('input[type=checkbox]').on('click', function (event) {
            if ($(event.target).hasClass('checked_all')) return ;
            $('.checked_all').prop('checked', false)}
        )
        $('.checked_all').on('click', function (event) {

            if (event.target.tagName != 'INPUT') {
                $(this).prop('checked', !$(this).prop('checked'))
            }

            $('input[type=checkbox]').prop('checked', $(this).prop('checked'))
        })

        $('.delete_archives').on('click', function () {
            var id = $('input[type=checkbox]:checked')
                .filter('input[name]')
                .map(function (index, item) {
                    return $(item).data('id')
                })
                .toArray().join()

            var token = "{{csrf_token()}}";
            layer.confirm('确认删除文章?', {
                title: '删除确认',
                btn: ['确认','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{{url('member/archives/modDestroy')}}" + '/' + id,
                    data:{_token:token},
                    type:'get',
                    success:function(data){
                        if(data=='success'){
                            layer.msg('删除成功!', {icon: 1});
                            $('input[type=checkbox]:checked')
                                .filter('input[name]')
                                .map(function (index, item) {
                                    return $(item).parents('tr').remove()
                                })
                        }else{
                            layer.msg('删除失败!', {icon: 2});
                        }
                    }
                });

            });
        })
    </script>
@endsection

@section('scripts')

@endsection